#!/bin/sh

# read wekan config
source $SNAP/bin/config

# TODO: uncomment following, once snapctl can be called from outside the hooks
# for key in ${keys[@]}
# do
#   # snappy is picky about key syntax, using mapping
#   MAP_KEY="KEY_$key"
#   SNAPPY_KEY=
#   if value=$(snapctl get ${!MAP_KEY}); then
#       echo "$key='$value'"
#       export $key=$value
#   else
#       # use default value
#       default_value="DEFAULT_$key"
#       echo "using default value: $key='${!default_value}'"
#       export $key=${!default_value}
#   fi
# done

# TODO: get rid of this workaround once above can be used
# loop through all values, and if not defined, use default value
for key in ${keys[@]}
do
  if [ "x" ==  "x${!key}" ]; then
      # use default value
      default_value="DEFAULT_$key"
      echo "using default value: $key='${!default_value}'"
      export $key=${!default_value}
      # echo "export $key='${!def_value}'" >> $SETTINGS_FILE
  else
      echo "$key='${!key}'"
  fi
done
